
<template>
  <app-dialog v-model="show" width="700px" style="margin-top: 3%" title="绑定账号" @open="handleOpen()">
    <div style="display: flex; justify-content: center">
      <el-form :model="formdata">
        <el-form-item label="平台">
          <el-input disabled v-model="formdata.sub_plant_name" style="width: 300px" />
        </el-form-item>
        <el-form-item label="账号">
          <el-input v-model="formdata.user_name" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="formdata.pass_word" />
        </el-form-item>
      </el-form>
    </div>

    <template #footer>
      <el-button @click="show = false">取消</el-button>
      <el-button type="primary" class="hovepcvicecolor" @click="handleSubmit()">确定</el-button>
    </template>
  </app-dialog>
</template>

<script setup>
import http from '@/utils/uc-http'
import { ElMessage } from 'element-plus'

const props = defineProps({
  activebilding: Object,
})
const userStore = useUserStore()

const formdata = ref({
  main_plant_code: '',
  sub_plant_code: '',
  sub_plant_name: '',
  user_name: '',
  pass_word: '',
})

const show = defineModel({ type: Boolean })
const emits = defineEmits()

const handleOpen = () => {
  formdata.value = {
    main_plant_code: userStore.packageJs.plantcode,
    sub_plant_code: props.activebilding.plant_code,
    sub_plant_name: props.activebilding.plant_name,
    user_name: '',
    pass_word: '',
  }
}

const handleSubmit = () => {
  let body = JSON.parse(JSON.stringify(formdata.value))
  delete body.sub_plant_name

  http.post('/user_combins', body).then(res => {
    show.value = false
    if (res.code != 200) {
      show.value = false
      userStore.checkInfo()
      ElMessage({
        message: res.msg,
        type: 'success',
      })
    } else {
      ElMessage.error(res.msg)
    }
  })
}
</script>

<style lang="scss" scoped>
</style>